<script lang="ts" setup>
import useTable from '@/hooks/useTable'
import { get, post, message, loadFile } from '@/utils'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const { formatColumns } = useTable()
const searchQuery = reactive({
  jobId: props.id,
})
const formRef = ref()
const actionRef = ref()

const pagination = {
  showPageSize: true,
  pageSize: 20,
}
const request = (params: any, sort: any, filters: any): Promise<any> => {
  return new Promise((resolve, reject) => {
    const query = { ...params, size: params.pageSize }
    Reflect.deleteProperty(query, 'pageSize')
    get(
      {
        url: '/server-system/admin/schedule/log/page',
        data: query,
      },
      ({ data, code }) => {
        resolve({
          data: data.records,
          total: data.total,
          success: code == 200,
        })
      }
    )
  })
}
const columns = formatColumns([
  { title: 'bean名称', dataIndex: 'beanName' },
  { title: '执行参数', dataIndex: 'params' },
  {
    title: '执行状态',
    dataIndex: 'status',
    valueEnum: {
      0: { text: '成功', status: 'Success' },
      1: { text: '失败', status: 'Error' },
    },
  },
  { title: '失败信息', dataIndex: 'error' },
  { title: '耗时(毫秒)', dataIndex: 'times' },
  { title: '执行时间', dataIndex: 'createTime' },
])
</script>
<template>
  <CModal v-model:visible="props.show" width="500px" title="运行日志" :footer="false" @cancel="emit('update:show', false)">
    <ProTable :columns="columns" :request="request" row-key="id" :form-ref="ref => (formRef = ref)" :pagination="pagination" header-title="" column-resizable :params="searchQuery" :bordered="{ cell: true }" :action-ref="ref => (actionRef = ref)">
      <template #option-render="{ dom, reset }"> </template>
    </ProTable>
  </CModal>
</template>
<style lang="less" scoped></style>
